<template>
  <div>
      <el-card>
        <div v-if="optionsM==1">
          SutdentCode：<el-input v-model="studentCodeSruch" placeholder="请输入Code"></el-input><el-button type="primary"  @click.native="getStudentCourseSerch()">搜索</el-button>
        </div>
        <el-button type="primary" icon="el-icon-edit" circle @click.native="inserts()"></el-button>
        <el-table
          :data="studentCourseData"
          style="width: 100%">
          <el-table-column prop="id" label="ID" width="80"></el-table-column>
          <el-table-column prop="studentCode" label="学号" width="110"></el-table-column>
          <el-table-column prop="courseCode" label="课程号" width="180"></el-table-column>
          <el-table-column prop="selectDate" label="选课时间" width="100"></el-table-column>
          <el-table-column prop="achievement" label="成绩" width="80"></el-table-column>
          
          <el-table-column label="操作" >
            <template slot-scope="scope">
              <div v-if="optionsM==1">
              <el-button type="primary" icon="el-icon-edit" circle @click="edit()"></el-button>
              </div>
              <el-button type="danger" icon="el-icon-delete" circle @click="deleteStudentCourse(scope.row)"></el-button>
            </template>
          </el-table-column>
         
        </el-table>
    </el-card>
    <div v-show="isShow">
      <el-card style="text-align:center">
        <div  v-if="insert" >
        SutdentCode：<el-input v-model="studentCode" placeholder="请输入Code"></el-input>
        <p></p>
        CourseCode：<el-input v-model="courseCode" placeholder="请输入Code"></el-input>
        <p></p>
        Achievement：<el-input v-model="achievement" placeholder="请输入Code"></el-input>
        <p></p>
        </div>
        <div v-else>
        SutdentCode：<el-input v-model="studentCode" placeholder="请输入Code"></el-input>
        <p></p>
        CourseCode：<el-input v-model="courseCode" placeholder="请输入Code"></el-input>
        <p></p>
        Achievement：<el-input v-model="achievement" placeholder="请输入Code"></el-input>
        <p></p>
        </div>
        
        <el-button v-if="insert" type="primary" @click.native="updates()">更新</el-button>
        <el-button v-else type="primary" @click.native="insertData()">新增</el-button>
        <el-button  @click.native="updateBack()">返回</el-button>
        
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  props: ['name','code','optionsM'],
  components: {
  },
  data() {
    return {
        studentCourseData:[],
        id:'',
        studentCodeSruch:'',
        studentCode:'',
        courseCode:'',
        selectDate:'',
        achievement:'',
        insert:false,
        isShow:false,
    };
  },
  computed: {
  },
  watch: {
  },
  created() {
  },
  methods: {
      getStudentCourse(){
           this.axios.get(`/SCS/studentCourse/selectStudentCourse?studentCode=${this.code}`).then(
              response=>{
                  this.studentCourseData=response.data
                  console.log(response)
              },
              error=>{
                  console.log(error)
              }
          )
          
		      
      },
      getStudentCourseSerch(){
           this.axios.get(`/SCS/studentCourse/selectStudentCourse?studentCode=${this.studentCodeSruch}`).then(
              response=>{
                  this.studentCourseData=response.data
                  console.log(response)
                  this.getStudentCourseSerch()
              },
              error=>{
                  console.log(error)
              }
          )
          
		      
      },
      updateBack(){
      this.isShow=false
    },
    edit(){
      this.isShow=true
      this.insert=true
    },
    inserts(){
        this.insert=false
        this.isShow=true
    },
    insertData(){
         this.axios.get(`/SCS/studentCourse/insertStudentCourse?studentCode=${this.studentCode}&achievement=${this.achievement}&courseCode=${this.courseCode}&selectDate=${this.selectDate}`
        ).then(
            response=>{
                console.log('1',response)
                this.$alert(`${response.data}`, '提示', {
                    confirmButtonText: '确定',
                })
                this.isShow=false
                this.getStudentCourse()
            },
            error=>{
                console.log('0',error)
            }
        )
    },
    updates(){
        this.axios.get(`/SCS/studentCourse/updateAchievement?studentCode=${this.studentCode}&achievement=${this.achievement}&courseCode=${this.courseCode}`
        ).then(
            response=>{
                console.log('1',response)
                this.$alert(`${response.data}`, '提示', {
                    confirmButtonText: '确定',
                })
                this.getStudentCourse()
            },
            error=>{
                console.log('0',error)
            }
        )
    },
    deleteStudentCourse(item){
      console.log(item)
      this.axios.get(`/SCS/studentCourse/deleteStudentCourse?studentCode=${item.studentCode}&courseCode=${item.courseCode}`,{
      }).then(
        response=>{
          this.$alert(`${response.data}`, '提示', {
              confirmButtonText: '确定',
          });
          this.getStudentCourse()
        },
        error=>{
          console.log(error)
        }
      )
    },
  },
  mounted(){
      this.getStudentCourse()
      var _this = this;
		      let yy = new Date().getFullYear();
		      let mm = new Date().getMonth()+1;
		      let dd = new Date().getDate();
		      let hh = new Date().getHours();
		      let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
		      let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
		      _this.selectDate = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
  }
};
</script>
<style scoped lang="less">
.el-input{
      width: 300px;
  }
</style>